﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="J_SearchProduct.ascx.cs"
    Inherits="Pub_Module_J_SearchProduct" %>

<script language="javascript" type="text/javascript">
    var Url='<%= ResolveClientUrl("~/")%>';
      $(document).ready(function() {    
          $("#divSearch").corner(); 
      });  
     
     $(window).load(function() {
            $str=Url+"Pub/Ajax/AjaxAutoComplete.aspx?TopicID=" + $('#<%= ddlTopic.ClientID%>').val()+"&CatID="+$('#<%= ddlCatalogue.ClientID%>').val()
            $("#<%= txtSearch.ClientID%>").autocomplete($str, {
				minChars: 1,
		        width: 300,		      
		        selectFirst: true
		        
	        
		      // autoFill: true,
	        });
	        
	       /*$("#aaa").result(function(event, data, formatted) {
		
	        });
            */

        });   
</script>

<div class="divBlock" style="background-color: #ADE506; width: 100%; white-space: nowrap;
    border: #d2b48c; text-align: center" id="divSearch">
    <div style="padding: 10px 10px 10px 10px;">
        <div>
            <asp:TextBox ID="txtSearch" runat="server" CssClass="txt_Common" Width="300px"  style="border:solid 1px #ADE506; font-size:12px;"></asp:TextBox>
            <asp:DropDownList ID="ddlTopic" runat="server" CssClass="ddl_Common"  onchange="fnGetcategoryID(this.options[this.selectedIndex].value,this)" Width="130px"  style="border:solid 1px #ADE506;">
            </asp:DropDownList>
            <asp:DropDownList ID="ddlCatalogue" runat="server" CssClass="ddl_Common" Width="130px" style="border:solid 1px #ADE506; ">
            </asp:DropDownList>
            <input type="button" value="Tìm kiếm" id="btnSearch" onclick="fnClickSearch()" style="height:24px"
                class="btn_Common" runat="server" /></div>
    </div>
</div>

<script language="javascript" type="text/javascript">
    function fnGetcategoryID(IDTopic,drl_ChuDe)
    {      
        var drl_TheLoai=document.getElementById("<%= ddlCatalogue.ClientID %>");
           drl_TheLoai.options.length=0;
           drl_TheLoai.options[0]=new Option("Loading...","");
     
        Pub_Module_J_SearchProduct.AjaxGetcategoryID(IDTopic,CallBackGetcategoryID)
    }
    function CallBackGetcategoryID(res)
    {
        if(res!=null)
        {
            var ds=res.value;
            if(ds!=null && typeof(ds)=="object" && ds.Tables!=null)
			{	
			    var drl_TheLoai=document.getElementById("<%= ddlCatalogue.ClientID %>");
				drl_TheLoai.options.length=0;
				var len=ds.Tables[0].Rows.length;	
				var TenTL="";
				var MaTL="";
				drl_TheLoai.options[0]=new Option("--Chọn thể loại--","");
				for(var i=0;i<len;i++)
				{	
					TenTL=ds.Tables[0].Rows[i].CatName;
					MaTL=ds.Tables[0].Rows[i].CatID;						
					drl_TheLoai.options[i+1]=new Option(TenTL,MaTL);
				}	
			}	
        }
    }
    
    function fnClickSearch()
    {
        var t=setTimeout("fnSearch()",500);
    }
    
    function fnSearch()
    { 
         
         var Url='<%= ResolveClientUrl("~/")%>';
         var txtSearch=document.getElementById("<%= txtSearch.ClientID %>");
         var strSearch=txtSearch.value;
         if(strSearch=="")
            return;
         if(strSearch.indexOf("\\")!=-1)
            strSearch=strSearch.substr(0, strSearch.indexOf("\\"));
         var ddlTopic=document.getElementById("<%= ddlTopic.ClientID %>");
         var ddlCatalogue=document.getElementById("<%= ddlCatalogue.ClientID %>");         
         window.location.href=Url+"SearchStall/search/"+ddlCatalogue.value+"/"+ddlTopic.value+"/"+strSearch+"/0.aspx";
    }
</script>

